<!--
 * @Author: your name
 * @Date: 2021-11-24 11:09:57
 * @LastEditTime: 2021-11-24 11:11:31
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \算法测试\day0906\mock数据.html
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        const fs = require('fs');
        var Mock = require('mockjs')
        var Random = require('mockjs').Random;
        //创建一定数量的sql语句
        function createSql(num) {
            var tempStr = '';
            for (var i = 0; i < num; i++) {

                //Random.name()
                var name = Mock.mock('@name');
                var sex = Math.random() > 0.5 ? 1 : 0;
                //Random.email()
                var email = Mock.mock('@email');
                // Random.integer(13000000000, 13999999999);
                var telephone = Mock.mock('@integer(13000000000, 13999999999)');
                // Random.cname(); 
                var leader = Mock.mock('@cname');
                // Random.date('yyyy-MM-dd');
                var create_time = Mock.mock('@date("yyyy-MM-dd")');
                var sql = `insert into tplay_example(name,sex,telephone,email,leader,create_time) values('${name}',${sex},'${telephone}','${email}','${leader}','${create_time}');`;

                tempStr += sql + "\r\n";
            }
            writeFile("mysql.sql", tempStr);
        }


        createSql(20);

        function writeFile(url, data = '') {

            fs.writeFile(url, data, 'utf8', function (err) {
                if (!err) {
                    console.log('创建完成');
                }
            });
        }
    </script>
</body>

</html>